package com.coder.baseapp.mvp.ui.activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.coder.baseapp.R;
import com.coder.baseapp.injecter.components.ActivityComponent;
import com.coder.baseapp.mvp.base.BaseActivity;
import com.coder.baseapp.mvp.contract.LoginContract;
import com.coder.baseapp.mvp.presenter.LoginPresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author: Tua.CoderGui
 * *
 * @Date: 2017/3/9
 * *
 * Copyright (c) 2017 All Rights Reserved.
 */
public class LoginActivity extends BaseActivity implements LoginContract.View {

    private static final String TAG = "LoginActivity";

    @Inject
    LoginPresenter mPresenter;

    ProgressDialog dialog;

    @BindView(R.id.tv_show)
    TextView mShowTextView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mPresenter.attachView(this);
        mPresenter.start();
    }

    @OnClick(value = {R.id.btn_login})
    public void onClick(View view) {
        mPresenter.login("admin", "pwd");
    }

    @Override
    protected void initInjector(ActivityComponent component) {
        component.inject(this);
    }

    @Override
    public void showLoading(boolean enable) {
        if (enable) {
            dialog = ProgressDialog.show(this, "", "正在加载中...");
        } else {
            dialog.dismiss();
            dialog = null;
        }
    }

    @Override
    public void showError(String msg) {
        showToastShort(msg);
        mShowTextView.append(msg + "\n");
    }

    @Override
    public void showSuccess() {
        showToastShort("success");
    }
}
